<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[3]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intType 		= $objRequest->getParam('type',0);
$strContent 	= $objRequest->getParam('content',null);
$intValue 		= $objRequest->getParam('val',0);
$strId 			= $objRequest->getParam('id',0);
$intError		= 0;
$intLike		= 0;
$strMessage		= '';
$strFullname	= '';
if(trim($strContent) == '' || !isset($strContent)) $intError = 1;
elseif(strlen(strip_tags($strContent)) < 2 && $strContent != '') $intError = 2;
if($intError == 0) {
	if($intType == 1) {		
		$objBlog 	= new Blog();	
		$intOwnerId	= 0;
		$intError	= $objBlog->addComment($AppUI->id, $intValue, Vfriend_Function::stripTags($strContent,2),$intOwnerId);
		if($intError == 0) {
			Vfriend_Function::deleteCookie('bcmt' . $intValue);
		} else {
			$intError	+= 12;
		}
	}elseif($intType == 2) {
		$objPhoto 	= new Photo();
		$intError	= $objPhoto->addComment($AppUI->id, $intValue, Vfriend_Function::stripTags($strContent,2),$intOwnerId);
		if($intError == 0) {
			Vfriend_Function::deleteCookie('pcmt' . $intValue);
		} else {
			$intError  	= 14;   
		}
	}elseif($intType == 3) {
		$objFullhouse 	= new Fullhouse();
		$intError		= $objFullhouse->addCmt($AppUI->id, $intValue, Vfriend_Function::stripTags($strContent,2), $intOwnerId);
		if($intError == 0) {
			Vfriend_Function::deleteCookie('ubcmt' . $intValue);
		} else {
			$intError  	= 14;   
		}
	}elseif($intType == 4) {
		$objOffline	= new Offline();
		$intError	= $objOffline->addCmt($AppUI->id, $intValue, Vfriend_Function::stripTags($strContent,2),$intOwnerId);
		if($intError == 0) {
			Vfriend_Function::deleteCookie('offcmt' . $intValue);			
		} else {
			$intError 		= 14;
		}
	}elseif($intType == 5) {
		$strQuote	= Vfriend_Function::getQuote($strContent);
		$strContent = Vfriend_Function::stripTags($strContent,3);
		$objNews	= new News();
		$intError	= $objNews->addComment($AppUI->id, $intValue, $strContent, $strQuote);
		if($intError == 0) {
			Vfriend_Function::deleteCookie('ncmt' . $intValue);			
		} else {
			$intError 		= 14;
		}
	}
	if($intError == 0) {
		$strMessage	= $arrMessage[1];
		$objBehaviour 	= new Behaviour();
		$objBehaviour->updateReadById($AppUI->id, $strId);		
		$arrBehaviour	= $objBehaviour->get($strId);
		$this->view->item	= $arrBehaviour;
		$this->view->type	= $intType;
		$this->view->ajax 	= 1;
		$objView	= Zend_Registry::get('objView');
		$strInfo	= $objView->fetch('index/box-behaviour-info.tpl');
		$strCmt		= $objView->fetch('index/box-behaviour-comment.tpl');
		$arrJson	= array('error'	=> $intError, 							
							'msg'	=> $strMessage,
							'dinfo'	=> $strInfo,
							'dcmt'	=> $strCmt,
							);
	}
}
if($intError > 0) {
	if($intOwnerId > 0) {
		$objVfriendUser = new Vfriend_User();
		$objUser		= $objVfriendUser->getFull($intOwnerId);
		$strFullname	= $objUser->fullnamevn;
	}
	$strError	= $arrError[$intError];
	$strError	= str_replace('[strFullname]', $strFullname, $strError);
	$arrJson 	= array('error'=>$intError,'msg'=>$strError);
}
echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
exit();
?>
